﻿using CMS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    //alt+enter
    //四个类都实现同意接口实现里面方法对应的实体类
    public class CargoTypeProvider : IProvider<CargoType>
    {
        private CargorDBModel1 db = new CargorDBModel1();
        //删除
        public int Delete(CargoType t)
        {
          if (t == null) return 0;
            var model = db.CargoType.ToList().FirstOrDefault(item => t.Id == item.Id);
            if (model == null) return 0;
            db.CargoType.Remove(model);
            int count = db.SaveChanges();
            return count;
        }
        //添加
        public int Insert(CargoType t)
        {
           if(t==null) return 0;
           if(string.IsNullOrEmpty(t.Name)||string.IsNullOrEmpty(t.MenberName))return 0;
           if(t.InserDate==null) return 0;
           db.CargoType.Add(t);
            int count=db.SaveChanges();
            return count;
            //成功等于1 不成功0
        }

        public List<CargoType> Select()
        {
           return db.CargoType.ToList();
        }
        //修改
        public int Update(CargoType t)
        {
            if (t == null) return 0;
            return 0;
        }
    }
}
